package todo_api

import (
	"github.com/daqing/airway/app/models"
	"github.com/daqing/airway/lib/db"
	"github.com/daqing/airway/lib/resp"
	"github.com/daqing/airway/lib/sql"
	"github.com/gin-gonic/gin"
)

type DeleteParams struct {
	Id int `json:"id"`
}

func DeleteAction(c *gin.Context) {
	var p DeleteParams

	if err := c.BindJSON(&p); err != nil {
		resp.Error(c, err)
		return
	}

	err := db.DeleteById[models.TodoItem](sql.IdType(p.Id))
	if err != nil {
		resp.Error(c, err)
		return
	}

	resp.Empty(c)
}
